package cn.study.luckyapp.activityrule.query;

import cn.hutool.core.collection.CollectionUtil;
import cn.study.luckyapp.assembler.ActivityRuleAssembler;
import cn.study.luckyclient.dto.data.ActivityRuleVo;
import cn.study.luckyclient.dto.query.ActivityRuleByParamQuery;
import cn.study.luckydomain.activityrule.ActivityRuleEntity;
import cn.study.luckydomain.gateway.ActivityRuleGateway;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
@AllArgsConstructor
public class ActivityRuleByParamQueryExe {
    private final ActivityRuleGateway activityRuleGateway;
    public List<ActivityRuleVo> execute(ActivityRuleByParamQuery query){
        List<ActivityRuleEntity> list = activityRuleGateway.list(query);

        if (CollectionUtil.isEmpty(list)) {
            return new ArrayList<>();
        }

        return new Page<ActivityRuleEntity>()
                .setRecords(list)
                .convert(ActivityRuleAssembler::toActivityRuleVO)
                .getRecords();
    }
}
